home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
stdio
/
c
/
tmpfile
< prev
next >
Wrap
Text File
|
1996-11-09
|
2KB
|
98 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/tmpfile,v $
* $Date: 1996/05/06 09:01:34 $
* $Revision: 1.2 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: tmpfile,v $
* Revision 1.2 1996/05/06 09:01:34 unixlib
* Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
* Saved for 3.7a release.
*
* Revision 1.1 1996/04/19 21:32:42 simon
* Initial revision
*
***************************************************************************/
static const char rcs_id[] = "$Id: tmpfile,v 1.2 1996/05/06 09:01:34 unixlib Rel $";
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
__STDIOLIB__
#define MKTEMP
FILE *
tmpfile (void)
{
if (__tmpf)
return (0);
tmpnam (__tmpn);
return (__tmpf = fopen (__tmpn, "wb+"));
}
static char *
__tmpnam (register char *buf, register char *dir,
register char *template)
{
register char *s = buf;
register int i, j = 0;
if (dir)
{
while (*s++ = *dir++);
s--;
*s++ = '/';
}
while (*s++ = *template++);
s -= 7;
if (*s != 'X')
return (0);
loop:i = __tmpcnt++, j++;
sprintf (s, "%.6x", i);
if (!access (buf, 0))
{
if ((__tmpcnt += 0x131) >= 0x1000000)
__tmpcnt &= 0x3ff;
if (j > 256)
return (0); /* max. 256 tries */
goto loop;
}
return (buf);
}
static char __tmpbuf[L_tmpnam + 1];
char *
tmpnam (register char *buf)
{
if (!buf)
buf = __tmpbuf;
return (__tmpnam (buf, P_tmpdir, "__XXXXXX"));
}
#ifdef MKTEMP
char *
mktemp (register char *template)
{
return (__tmpnam (template, 0, template));
}
int
mkstemp (char *template)
{
return (open (mktemp (template), O_RDWR | O_CREAT | O_TRUNC, 0666));
}
#endif